﻿using Nova_Common.Extend;
using Nova_DAL;
using Nova_MOD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nova_BLL
{
    public class TCommandsHisBll
    {
        private readonly TCommandsHisDal dal = new TCommandsHisDal();

        public bool InsertEntity(TCommandsHis entity)
        {
            string id = dal.Insert(entity);
            return !id.IsEmpty();
        }

        public bool InsertEntity(TCommands cmdEntity,int finishResult, int finishMethod)
        {
            TCommandsHis cmdHisEntity = new TCommandsHis();
            cmdHisEntity.TaskID = cmdEntity.TaskID;
            cmdHisEntity.TaskMode = cmdEntity.TaskMode;
            cmdHisEntity.Tray_ID = cmdEntity.Tray_ID;
            cmdHisEntity.PosS_ID = cmdEntity.PosS_ID;
            cmdHisEntity.PosE_ID = cmdEntity.PosE_ID;
            cmdHisEntity.EquipmentS_ID = cmdEntity.EquipmentS_ID;
            cmdHisEntity.EquipmentE_ID = cmdEntity.EquipmentE_ID;
            cmdHisEntity.TaskStatus = cmdEntity.TaskMode;
            cmdHisEntity.WriteToPLC = cmdEntity.WriteToPLC;
            cmdHisEntity.SyncWCS = cmdEntity.SyncWCS;
            cmdHisEntity.Step = cmdEntity.Step;
            cmdHisEntity.CommandOrder = cmdEntity.CommandOrder;
            cmdHisEntity.ErrorNo = cmdEntity.ErrorNo;
            cmdHisEntity.ErrorComment = cmdEntity.ErrorComment;
            cmdHisEntity.CDT = cmdEntity.CDT;
            cmdHisEntity.User_Name = cmdEntity.User_Name;
            cmdHisEntity.FinishResult = 2; // 1:完成 2：取消
            cmdHisEntity.FinishMethod = 2; // 0：WCS自动  1：RF人工  2：WMS人工
            cmdHisEntity.FinishTime = DateTime.Now;
            string id = dal.Insert(cmdHisEntity);
            return !id.IsEmpty();
        }
    }
}
